package com.lilang.a0608provider;

import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText tv1;
    private EditText bookname;
    private EditText tv2;
    private EditText author;
    private Button add;
    private Button coll;
    Uri uri;
    String path="content://com.lilang.a0608provider/";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        tv1 = (EditText) findViewById(R.id.tv1);
        bookname = (EditText) findViewById(R.id.bookname);
        tv2 = (EditText) findViewById(R.id.tv2);
        author = (EditText) findViewById(R.id.author);
        add = (Button) findViewById(R.id.add);
        coll = (Button) findViewById(R.id.coll);
        add.setOnClickListener(this);
        coll.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.add:
                String addPath=path+"insert_book";
                uri = Uri.parse(addPath);
                ContentValues values=new ContentValues();
                values.put("bookname",bookname.getText().toString().trim());
                values.put("author",author.getText().toString().trim());
                getContentResolver().insert(uri,values);
                break;
            case R.id.coll:
                Intent intent=new Intent(this,Main2Activity.class);
                startActivity(intent);
                break;
        }
    }
}
